<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>系统公告</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
 <link rel="stylesheet" href="${ctx}/resources/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" type="text/css" href="${ctx}/resources/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/resources/css/wu.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/resources/css/icon.css" />
<link href="${ctx}/resources/umeditor/themes/default/css/umeditor.css" type="text/css"
	rel="stylesheet">
<script type="text/javascript" src="${ctx}/resources/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript"
	src="${ctx}/resources/umeditor/third-party/template.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/umeditor/umeditor.config.js"></script>
<script type="text/javascript" src="${ctx}/resources/umeditor/umeditor.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/umeditor/lang/zh-cn/zh-cn.js"></script>
<script src="${ctx}/resources/js/pintuer.js"></script>

  </head>
  <body>
  <script type="text/javascript">
    $(function(){
    	 //设置富文本编辑器上传文件的保存的路径
    	window.UMEDITOR_HOME_URL = "${ctx}/resources/umeditor/";
    });
  </script>
  
  
  <div class="easyui-panel" data-options="title:'查询条件',iconCls:'icon-search'" style="width:100%;">
		<form id="searchFrm" method="get">
			<table width="100%" cellpadding="10" >
				<tr>
					<td width="50%"> 
					<input class="easyui-textbox" name="title"
							data-options="label:'新闻标题:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
					<td width="50%">
					<input class="easyui-textbox" name="content"
							data-options="label:'新闻内容:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
				</tr>
				<tr>
					<td width="50%">
					<input class="easyui-textbox" name="startDate"
							data-options="label:'开始日期:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
					<td width="50%">
					<input class="easyui-textbox" name="endDate"
							data-options="label:'结束日期:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
				</tr>
				<tr>
					<td colspan="3" align="center">
						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="doSearch()" data-options="iconCls:'icon-search'">查询</a>
						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#searchFrm').form('clear')" data-options="iconCls:'icon-reload'">重置</a>
						
					</td>
				</tr>
			</table>
		</form>
	</div>
	

	
	
<!-- 查询条件结束 -->
	 <div style="height: 2px"></div>
	 <!-- 数据表格开始 -->
    <table id="table" class="easyui-datagrid" style="width:100%;height:300px">
    </table>
    
	<div id="tb">

		<a href="javascript:void(0)" class="easyui-linkbutton" id="addNews" data-options="iconCls:'icon-add',plain:true">添加公告</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" id="updateNews" data-options="iconCls:'icon-edit',plain:true">修改公告</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" id="deleteNews" data-options="iconCls:'icon-remove',plain:true">删除公告</a>
	</div>
	
	
	<!-- 添加和修改用户的弹出层 开始 -->
	<div id="dlg" class="easyui-dialog" style="width:800px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
        <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
                <input type="hidden" name="id"  id="newsid"   >
            
            <div style="margin-bottom:10px">
                <input name="title" class="easyui-textbox" required="true" label="新闻标题:" style="width:100%">
            </div>                               
               <div style="margin-bottom:10px"> 
                	<div >
						<label>新闻内容：</label>
					</div>
					<div >				
					<!-- 	<textarea name="context" class="input w80"
							style="width:500px;height:300px"></textarea> -->
							  <!-- 产生富文本编辑器的区域 -->
							<script type="text/plain"  id="content" name="content" style="width:500px;height:300px"></script>
							<script type="text/javascript">
							 //实例化编辑器，显示在页面，参数是上面的id
							 var  um=UM.getEditor('content');
							</script>
					</div>
            </div>
           
        </form>
    </div>
    
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveNews()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    
	 <div id="sj" class="easyui-panel" data-options="title:'学姐',iconCls:'icon-search'" style="width:100%;"></div>
	
	<!-- 添加和修改用户的弹出层 结束-->
	<script type="text/javascript">
	$("#table").datagrid({
		title:'用户列表',
		singleSelect:true,
		collapsible:true,
        fitColumns:true,
        pagination:true,
      /*   pagePosition:'both', */
       pageSize:5,
        pageList:[5,10,15,20], 
        rownumbers:true,
        toolbar:'#tb',               //添加，修改和删除的标签
        url:'${ctx}/news/loadAllNews.action',
       // method:'get',
        columns:[[
                  {field:'id',title:'新闻编号',align:'center',width:100},
                  {field:'title',title:'新闻标题',align:'center',width:100},
                  {field:'content',title:'新闻内容',align:'center',width:100},
                  {field:'createtime',title:'发布时间',align:'center',width:100},
                  {field:'opername',title:'发布人',align:'center',width:100},
              ]],
              onDblClickRow: function (rowIndex,rowData) {
            	  showSelectedSurveryDataOnMap(rowData);
              }
	});
	//双击事件
	var showSelectedSurveryDataOnMap=function(rowData){

		if(rowData.content){
			$("#xj").dialog("open").dialog('setTitle','禁止一切');
			//alert(rowData.content);
			$("#xj").html("最美");
		}
		}
	
		//查询
		function doSearch(){
			var params=$("#searchFrm").serialize();
			alert(params);
			$("#table").datagrid({           //Query data with some parameters.利用参数查询
				url:'${ctx}/news/loadAllNews.action?'+params
			});
		};
		 
		
		//打开添加用户的弹出层
		var url="";
		$("#addNews").click(function(){
			$("#dlg").dialog("open").dialog('setTitle','添加公告');
			$("#fm").form("clear");//清空表格
			//设置id只读
			//$("#newsid").textbox('editable',false);
			url="${ctx}/news/addNews.action";
		});
		//打开修改的弹出层
		$("#updateNews").click(function(){
			//得到当前行
			var row=$("#table").datagrid('getSelected');
			if(row){
				$("#dlg").dialog("open").dialog('setTitle','修改客户');
				//表单数据装载
				$("#fm").form("load",row);
				//设置identity只读
				$("#id").textbox('readonly',true);
				url="${ctx}/news/updateNews.action";
			}else{
				$.messager.show({
					title:'提示',
					msg:'请选中操作行'
				});
			}
		});
		
		
		//保存
		function saveNews(){
			$.messager.progress();	// 显示进度条
			$('#fm').form('submit', {
				url: url,                                  //数据提交地址  user/addNews.action
				onSubmit: function(){
					var isValid = $(this).form('validate');//对表单里面的required:true和vailType的数据进行验证
					if (!isValid){
						$.messager.progress('close');	    // 如果验证失败关闭进度条
					}
					return isValid;	                  //返回验证结果
				},
				success: function(obj){               //如果提交成功之后回调的方法
					$.messager.progress('close');	  // 关闭进度条
                    var result = eval('('+obj+')');    //把obj的josn字符串转成js认识的json对象
					$.messager.show({
						title:'提示',
						msg:result.msg
					});
					$("#table").datagrid("reload");    //刷新数据表格
					$("#dlg").dialog("close");         //关闭弹出层
				}
			});
		}	
		
		
		
		//删除用户
		$("#deleteNews").click(function(){
			//得到当前行
			var row=$("#table").datagrid('getSelected');
			if(row){
				$.messager.confirm('提示','你确定要删除'+row.title+'这个新闻吗?',function(r){
                    if (r){
                        $.post('${ctx}/news/deleteNews.action',{id:row.id},function(result){
                                $.messager.show({    
                                    title: '提示',
                                    msg: '删除成功'
                                });
                                $("#table").datagrid("reload");//刷新表格
                        },'json');
                    }
                });
			}else{
				$.messager.show({
					title:'提示',
					msg:'请选中操作行'
				});
			}
		});	
	
		
	
	
	</script>
    
  </body>
</html>
